package com.mjp.learn.design.singleton;

/**
 * 懒汉式单例模式
 * 保证没有需要时,实例没有加载,但是会导致线程不安全
 */
public class Mg02 {
    private static Mg02 INSTANCE;

    private Mg02(){}

    public static Mg02 getInstance() {
        if(INSTANCE == null) {
            INSTANCE = new Mg02();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for(int i = 0; i < 100;i++){
            new Thread(()->{
                System.out.println(Mg02.getInstance().hashCode());
            }).start();
        }
    }
}
